package sz.szsmk.citizencard.ui.newversion.fragment.adapter

import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo
import sz.szsmk.citizencard.util.JumpThirdView
import sz.szsmk.citizencard.util.JumpUtils

/**
 *  author : hyt
 *  date : 2020/10/28
 *  description :
 */
class HomeTopBannerAdapter (var context: Context?=null, data: List<AdInfo>) :
        BannerAdapter<AdInfo, HomeTopBannerAdapter.BannerViewHolder>(data) {
    var extend :String?=""

    fun setData(extend :String?){
        this.extend=extend
    }
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder? {
        val imageView = ImageView(parent.getContext())
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT)
        imageView.scaleType = ImageView.ScaleType.FIT_XY
        return BannerViewHolder(imageView)
    }

    override fun onBindView(holder: BannerViewHolder, data: AdInfo, position: Int, size: Int) {
        context?.let {
                Glide.with(it).load(data.resource_url)
                    .into(holder.imageView)

            holder.imageView.setOnClickListener{view->
                if(!TextUtils.isEmpty( data.link_url)){
                    //"https://huodong.szsmk.com/hd/xxnk/index?access_token="+extend
                    Log.i("msgs",data.resource_name+"   "+data.link_url+"    "+extend)
                    JumpThirdView.baseToJumpView(context, data.link_url, data.sys_label, data.need_header, "")
                }
            }
        }
    }


    class BannerViewHolder(view: ImageView) : RecyclerView.ViewHolder(view) {
        var imageView: ImageView = view
    }
}